import time
import unittest

from configparser import ConfigParser

from Pages.intFlightPage import intFlightPage
from Pages.AdminPage import AdminPage
from Pages.OrderListPage import OrderListPage
from Pages.tripPage import tripPage
from Pages.OBTintFlightDetailPage import OBTintFlightDetailPage
from Pages.adminIntFlightDetailPage import adminIntFlightDetailPage
from Public import Gl
from Public.Login import Login



class intFlightTicket(unittest.TestCase):
    # 定义类属性存储订单号（全局共享）
    global_order_no = None
    global_refund_OrderNo = None
    def setUp(self):
        parse = ConfigParser()
        #win需使用配置文件绝对路径
        parse.read('D:\zidonghua\dtsl-master5\dtsl-master3\dtsl-master\DTSL\Public\configurations.ini')
        self.driver = Gl.BrowserEngine(self).open_browser(self)
        self.L = Login()
        self.urlOBT = parse.get('OBT','url')
        self.useridOBT = parse.get('OBT','userid')
        self.passwordOBT = parse.get('OBT','password')
        self.urlAdmin = parse.get('admin','url')
        self.useridAdmin = parse.get('admin','userid')
        self.passwordAdmin = parse.get('admin','password')

    def tearDown(self):
        #self.driver.quit()
        pass


    def test_001searchAndBook(self):
        PP = intFlightPage()
        self.L.LoginOBT(self.urlOBT,  self.useridOBT, self.passwordOBT)
        #PP.closeNotice()

        PP.switchToIntFlight()
        time.sleep(3)
        PP.select_intFlightFromCity()
        time.sleep(1)
        PP.select_intFlightToCity()
        time.sleep(3)
        PP.select_intFlightGoDate()
        time.sleep(3)
        PP.click_searchBtn(0)
        time.sleep(10)

        #选择航班
        PP.intFlight_reBuyPlaneTiket(2)
        time.sleep(3)
        PP.ignoreRecommend()
        time.sleep(3)

        #点击提交
        PP.click_submitPlane()
        time.sleep(5)
        TP = tripPage()
        TP.submitTrip()
        time.sleep(8)

        TP.goIFDetail()
        time.sleep(5)
        flightDetailPage = OBTintFlightDetailPage()
        intFlightTicket.flightOrderNo = flightDetailPage.getOrderNo()
        # print(planeTicket.flightOrderNo)
        print(f"首次购票后的订单号：{intFlightTicket.flightOrderNo}")
        time.sleep(10)

        #获取订单号
        #TP.goIFDetail()
        #time.sleep(3)
        #flightDetailPage = OBTintFlightDetailPage()
        #intFlightTicket.flightOrderNo = flightDetailPage.getOrderNo()
        #print(intFlightTicket.flightOrderNo)
        #time.sleep(3)


        #改签航班
        # flightDetailPage = OBTintFlightDetailPage()
        flightDetailPage.startChange()
        time.sleep(5)

        #PP.reBuyintPlaneTiket(1)  #控制买第n趟的航班,index从1开始
        PP.reBugGoIntTicket()
        time.sleep(10)
        flightDetailPage.submitChange()
        time.sleep(5)
        # intFlightTicket.changeOrderNo = flightDetailPage.getOrderNo()
        change_Order_No = flightDetailPage.getOrderNo()
        intFlightTicket.global_order_no = change_Order_No
        time.sleep(5)
        print(f"改签后的订单号：{change_Order_No}")

    def test_02flightChange(self):
        #登录后台
        AP = AdminPage()
        self.L.LoginAdmin(self.urlAdmin, self.useridAdmin, self.passwordAdmin)
        AP.goToFlightOrder()
        AF = adminIntFlightDetailPage()
        #AP.selectOrder(intFlightTicket.flightOrderNo)    出票的订单号
        print(f'管家后台处理的改签订单号：{intFlightTicket.global_order_no}')
        AP.selectOrder(intFlightTicket.global_order_no)
        time.sleep(3)
        AF.ticketingOperate()
        time.sleep(10)
        #提交出票
        #AF.SubmitOperate()
        #进行改签操作
        AF.confirmChange()
        AF.operateChange()

    def test_03chooseOrderToRefund(self):
        #前台退票
        PP = intFlightPage()
        self.L.LoginOBT(self.urlOBT,  self.useridOBT, self.passwordOBT)
        PP.goOrderList()
        OL = OrderListPage()
        time.sleep(3)
        OL.selectOrder(intFlightTicket.global_order_no)
        time.sleep(2)
        flightDetailPage = OBTintFlightDetailPage()
        flightDetailPage.applyTicketRefund()

        intFlightTicket.refundOrderNo = flightDetailPage.getOrderNo()
        intFlightTicket.global_refund_OrderNo = intFlightTicket.refundOrderNo
        print(f'前台申请退票后的订单号：{intFlightTicket.refundOrderNo}')
        return intFlightTicket.global_refund_OrderNo
        time.sleep(2)

    def test_04flightRefund(self):
        #后台退票
        AP = AdminPage()
        self.L.LoginAdmin(self.urlAdmin, self.useridAdmin, self.passwordAdmin)
        AP.goToFlightOrder()
        AF = adminIntFlightDetailPage()
        #AP.selectOrder(intFlightTicket.flightOrderNo)    出票的订单号
        AP.selectOrder(intFlightTicket.global_refund_OrderNo)
        AF.confirmRefund()
        print("国际机票退票成功")



if __name__ == '__main__':
    unittest.main()
